package com.ruoyi.novel.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.novel.domain.BookDelete;
import com.ruoyi.novel.domain.BookDeleteDTO;
import com.ruoyi.novel.domain.Bookshelf;
import com.ruoyi.novel.domain.BookshelfShow;
import com.ruoyi.novel.mapper.BookshelfMapper;
import com.ruoyi.novel.service.BookShelfService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 书架Controller
 */
@RestController
@RequestMapping("/bookshelf")
public class BookshelfController extends BaseController {
    @Autowired
    private BookShelfService bookShelfService;
    /**
     * 根据用户id查询书架
     */
    @GetMapping("/getBookShelfByUserId")
    public TableDataInfo getBookShelfByUserId(@RequestParam("userId") Long userId){
        List<BookshelfShow> bookShelfByUserId = bookShelfService.getBookShelfByUserId(userId);
        return getDataTable(bookShelfByUserId);
    }
    /**
     * 添加书架
     */
    @PutMapping("/addBookShelf")
    public AjaxResult addBookShelf(@RequestParam("userId") Long userId, @RequestParam("title") String title){
        return AjaxResult.success(bookShelfService.addBookShelf(userId,title));
    }
    /**
     * 查询该书是否在书架中
     */
    @GetMapping("/isInBookShelf")
    public AjaxResult isInBookShelf(@RequestParam("userId") Long userId, @RequestParam("title")String title){
        return AjaxResult.success(bookShelfService.isInBookShelf(userId,title));
    }
    /**
     * 根据用户id和小说名删除书架
     */
    @DeleteMapping("/deleteBookShelf")
    public AjaxResult deleteBookShelf(@RequestBody BookDelete bookDelete){
        return AjaxResult.success(bookShelfService.deleteBookShelf(bookDelete));
    }
    /**
     * 根据用户id和小说名批量删除书架
     */
    @DeleteMapping("/deleteBatchBookShelf")
    public AjaxResult deleteBatchBookShelf(@RequestBody BookDeleteDTO bookDeleteDTO){
        return AjaxResult.success(bookShelfService.deleteBatchBookShelf(bookDeleteDTO));
    }
}
